package com.itheima.health.controller;


import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.MemberService;
import com.itheima.health.service.SmsService;
import com.itheima.health.vo.SmsLoginParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/mobile/login")
public class LoginController {
    @DubboReference
    SmsService smsService;
    @DubboReference
    MemberService memberService;

    /**
     * @Author: JASON
     * @Date: 9:26 2021/1/13
     * @Parms [param]
     * @ReturnType: com.itheima.health.entity.Result
     * @Description: 短信登录
    */
    @RequestMapping("smsLogin")
    public Result smsLogin(@RequestBody SmsLoginParam param){
        log.info("[登录-短信登录]data：{}",param);
        boolean isSuccess = smsService.checkValidateCode("MOBILE_SIGNIN", param.getTeltphone(), param.getValidateCode());
        if(!isSuccess){
            return new Result(false, MessageConst.VALIDATECODE_ERROR);
        }
        Member member = new Member();
        member.setPhoneNumber(param.getTeltphone());
        Integer memberId = memberService.add(member);
        //登录（模拟，直接输出成功）
        log.info("[登录成功]》》》》》》》》》》》》》》》》》》》》》》》》{}", memberId);
        return new Result(true, MessageConst.LOGIN_SUCCESS);
    }

}
